package com.itqf;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2021/1/21
 * @Time: 上午10:08
 */
public class MySerializer extends JsonSerializer<Double> {

    @Override
    public void serialize(Double aDouble, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {

        //四舍五入
        String r =  "￥"+BigDecimal.valueOf(aDouble).setScale(2,BigDecimal.ROUND_HALF_UP).toString()+"元";
        //处理后的结果响应给客户端
        jsonGenerator.writeString(r);

    }
}
